<?php
/*
YHM (Your Hosting Manager) - Copyright 2010 All Rights Reserved. - YHM Group
Released under the Simplified BSD Licence.

Website: http://yhm.co.uk
Licence: http://yhm.co.uk/about/#licence

file: client/announcements.php
author: Kieran D. (Polarbear541)
*/

//Init Includes, Sessions and Page Info
require_once("../global.php");
session_start();
checklogin_client();
$username = $_SESSION['user_name'];
$page = "announcements";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>YHM - Client CP - Announcements</title>
<meta http-equiv="Content-Language" content="English" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="../style.css" media="screen" />
</head>
<body>

<?php include("./header.php"); ?>

<div id="content">

	<h2>Announcements</h2>

	<?php
	//Assign Variables
	$aid = mysql_real_escape_string($_GET['aid']);

	if(empty($aid)) //If Announcement ID is empty then show all
	{
		//Query to run
		$query = mysql_query("SELECT * FROM ".TABLE_PREFIX."announcements ORDER BY id DESC LIMIT 0,5");

		//Display Announcements
		while($row = mysql_fetch_array($query))
		{
			echo "<h3>{$row['title']}</h3>";
			echo substr($row['message'],0,100) . "... <br /><a href='./announcements.php?aid={$row['id']}'>Read More...</a><br />";
		}
	}

	else //Else show specific announcement
	{
		//Run queries to get announcement info
		$query = mysql_query("SELECT * FROM ".TABLE_PREFIX."announcements WHERE id='$aid'");
		$row = mysql_fetch_array($query);
		
		if (!$row) //If no result show not found error
		{
			echo "Announcement Not Found <br />";
		}

		else //Else show announcement info
		{
			echo "<h3>Announcement: {$row['title']}</h3>";
			echo $row['message'];
		}
		
		//Show back link
		echo "<br /><a href='announcements.php'>Back to announcements</a>";
	}
	?>
	
	<?php require_once("../footer.php"); ?>

</div>
</body>
</html>